#include "get_file_type.h"
/* 通过文件名获取文件的类型*/
const char* get_file_type(const char* name){
    char *dot;

    // 从右到左查找“.”字符，如果不存在则返回NULL
    dot = strrchr(name, '.');
    if(dot == NULL){
        return "text/plain; charset=utf-8";
    }
    if(strcmp(dot, ".html") == 0 || strcmp(dot, ".thm") == 0)
        return "Content-Type: text/html; charset=utf-8";
    else if(strcmp(dot, ".jpg") == 0 ||  strcmp(dot, ".jpeg") == 0)
        return "Content-Type: image/jpeg";
    else if(strcmp(dot, ".gif") == 0)
        return "Content-Type: image/gif";
    else if(strcmp(dot, ".png") == 0)
        return "Content-Type: image/png";
    else if(strcmp(dot, ".css") == 0)
        return "Content-Type: text/css";
    else if(strcmp(dot, ".au") == 0)
        return "Content-Type: audio/basic";
    else if(strcmp(dot, ".wav") == 0)
        return "Content-Type: audio/wav";
    else if(strcmp(dot, ".avi") == 0)
        return "Content-Type: audio/x-msvideo";
    else if(strcmp(dot, ".mov") == 0 || strcmp(dot, ".qt") == 0)
        return "Content-Type: audio/quicktiime";
    else if(strcmp(dot, ".mpeg") == 0 || strcmp(dot, ".mpe") == 0)
        return "Content-Type: video/mpeg";
    else if(strcmp(dot, ".vrml") == 0 || strcmp(dot, ".wrl") == 0)
        return "Content-Type: video/vrml";
    else if(strcmp(dot, ".midi") ==0 || strcmp(dot, ".mid") == 0)
        return "Content-Type: video/midi";
    else if(strcmp(dot, ".mp3") == 0)
        return "Content-Type: audio/mpeg";
    else if(strcmp(dot, ".ogg") == 0)
        return "Content-Type: application/ogg";
    else if(strcmp(dot, ".pac") == 0)
        return "Content-Type: application/x-ns-proxy-autoconfig";
    else 
        return "Content-Type: text/plain; charset=utf-8";
}